#include "const.h"

int build(var_t v, size_t i, void *p__) {
	char targetconfig[256], *p;

	if (v||i||p__) {/*unused*/}

	i_strcpy(targetconfig, sizeof(targetconfig), v_getvar("target"));

	if (isverbose()) {
		fprintf(stdout, "active target is \"%s\"\n", targetconfig);
		fflush(stdout);
	}

	if ((p=strchr(targetconfig, '.')) != (char *)0)
		*p = 0;

	v_setvar("targetsys", targetconfig);
	if (!loadtoolchaindefaults()) {
		fprintf(stderr, "warning: target \"%s\" is not supported; ignoring\n",
			targetconfig);
		fflush(stderr);

		return 0;
	}

	v_setvar("targetarch", p ? &p[1]
		: v_getvar(v_format("$(targetsys).defaultarch")));

	return v_foreach(v_var("projectfiles"), buildproject, (void *)0);
}
